package com.samsung.app;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

public class ExToast
{
  private static final int MSG_TOAST_TIMEOUT = 1;
  private static ExToast mExToast = new ExToast();
  private LinkedList<String> mQueue = new LinkedList<String>();
  private Handler mToastHandler = new Handler()
  {
    public void handleMessage(Message paramMessage)
    {
      switch (paramMessage.what)
      {
      default:
    	  return;
      case 1:
    	  synchronized (ExToast.this.mToastMap)
          {
            String str1 = (String)paramMessage.obj;
            ExToast.this.hide(Integer.parseInt(str1));
            ExToast.this.mQueue.remove(str1);
            if (!ExToast.this.mQueue.isEmpty())
            {
              String str2 = (String)ExToast.this.mQueue.getFirst();
              ExToast.this.doShow(str2);
            }
          }
      }
    }
  };
  private HashMap<String, MyToast> mToastMap = new HashMap<String, MyToast>();

  private void doShow(String paramString)
  {
    MyToast localMyToast = (MyToast)this.mToastMap.get(paramString);
    if (localMyToast != null)
    {
      localMyToast.mRunning = true;
      localMyToast.mToast.show();
      setTimeout(localMyToast.mTerm, paramString);
    }
  }

  /** @deprecated */
  public static ExToast getInstance()
  {
      ExToast localExToast = mExToast;
      return localExToast;
  }

  private Toast makeToast(Context paramContext, View paramView, int paramInt)
  {
    Toast localToast = new Toast(paramContext);
    localToast.setView(paramView);
    localToast.setDuration(paramInt);
    return localToast;
  }

  private View makeView(Context paramContext, int paramInt1, int paramInt2)
  {
    TextView localTextView = new TextView(paramContext);
    localTextView.setGravity(17);
    localTextView.setBackgroundResource(2130837618);
    localTextView.setText(Html.fromHtml("<b>" + paramContext.getString(paramInt2) + "</b>"));
    localTextView.setTextSize(paramInt1);
    return localTextView;
  }

  private void setTimeout(int paramInt, String paramString)
  {
    if (paramInt == 0);

    int i = 2500;
      Message localMessage = new Message();
      localMessage.what = 1;
      localMessage.obj = paramString;
      this.mToastHandler.sendMessageDelayed(localMessage, i);
      return;
 
  }

  /** @deprecated */
  public void hide(int paramInt)
  {
      this.mQueue.remove(paramInt);
      MyToast localMyToast = (MyToast)this.mToastMap.get(paramInt);
      if ((localMyToast != null) && (localMyToast.mToast != null))
      {
        localMyToast.mToast.cancel();
        localMyToast.mRunning = false;
      }
  }

  /** @deprecated */
  public void hideAll(){
      this.mQueue.clear();
      Iterator<String> localIterator = this.mToastMap.keySet().iterator();
      while (true)
      {
        boolean bool = localIterator.hasNext();
        if (!bool)
          return;
        String str = (String)localIterator.next();
        if (str == null)
          continue;
        MyToast localMyToast = (MyToast)this.mToastMap.get(str);
        if ((localMyToast == null) || (localMyToast.mToast == null))
          continue;
        localMyToast.mToast.cancel();
        localMyToast.mRunning = false;
      }
  }

  /** @deprecated */
  public boolean isShowing()
  {

      Iterator<String> localIterator = this.mToastMap.keySet().iterator();
      while (true)
      {
        boolean bool1 = localIterator.hasNext();
        if (!bool1)
          return false;
        String str = (String)localIterator.next();
        if (str == null)
          continue;
        MyToast localMyToast = (MyToast)this.mToastMap.get(str);
        if (localMyToast == null)
          continue;
        boolean bool2 = localMyToast.mRunning;
        if (!bool2)
          continue;
        return true;
      }
 
  }

  /** @deprecated */
  public void register(Context paramContext, String paramInt1, int paramInt2, int paramInt3){

      MyToast localMyToast = new MyToast();
      localMyToast.mToast = makeToast(paramContext, makeView(paramContext, 12, paramInt2), paramInt3);
      localMyToast.mTerm = paramInt3;
      localMyToast.mRunning = false;
      this.mToastMap.put(paramInt1, localMyToast);
      
      return;

  }

  /** @deprecated */
  public void show(String paramInt){
      MyToast localMyToast = (MyToast)this.mToastMap.get(paramInt);
      int i;
      if (localMyToast != null)
      {
        i = 0;

        for(String show :  this.mQueue){
        	if ((show).equalsIgnoreCase(paramInt)){
        		i=1;
        	}
        boolean bool = localMyToast.mRunning;
        if ((!bool) && (i == 0)){
        	this.mQueue.add(paramInt);
        if (this.mQueue.size() != 1)
          continue;
        doShow(paramInt);
        }
      }
   
  }

  }

  /** @deprecated */
  public void unregister(int paramInt)
  {
      hide(paramInt);
      this.mToastMap.remove(paramInt);
  }

  /** @deprecated */
  public void unregisterAll()
  {
      hideAll();
      this.mToastMap.clear();
  }

  private class MyToast
  {
    boolean mRunning;
    int mTerm;
    Toast mToast;

    private MyToast()
    {
    }
  }
}
